package com.company.management.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.company.management.controller.report.vo.UserDepVO;
import com.company.management.utils.Pageables;
import com.company.management.dto.UserDto;
import com.company.management.modal.entity.User;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Description:
 * @Author: zyj
 * @Date: 2022-09-6 9:23
 * @Version v1.0
 **/
@Repository
public interface UserMapper extends BaseMapper<User> {

    UserDto getByUserId(int id);

    UserDto getByToken(String token);

    UserDto findUserByUserName(String userName);

    UserDto findUserByUserNameAndPwd(String userName, String password);

    int save(User user);

    int update(User user);

    List<UserDepVO> selectUserDep(@Param("userId") long userId);


    @Select("select * from t_user ")
    List<User> listPage(Pageables pageables);

    @Select("select u.* from t_user u where u.user_name=#{username} and u.password=#{password}")
    User login(@Param(value = "username") String username, @Param(value = "password") String password);

    @Update("update t_user set token=#{token}, " +
            "token_update_time=#{tokenUpdateTime} " +
            " where user_name=#{userName} "
    )
    void updateToken(User user);

    @Update("update t_user set token='' " +
            " where user_id=#{userId} "
    )
    void logout(User user);

    List<UserDto> listAll();

    int batchUpdateUsers(List<User> users);

    /*@Update("update t_user set token='' " +
            " where user_name=#{userName} "
    )
    void logout(User user);*/


}
